﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->

<title>維護主機</title>

<script type="text/javascript">

function testHostConnection() {
	windowFreeze("連線測試中...");
	
	$.ajax({type:"post",url:"ChkHostConnection",dataType:"text",async:false,
		data:{ip:$("#hostIP").val(),loginId:$("#loginId").val(),loginPwd:$("#loginPWD").val()},
		success : function(res) {
			windowUnfreeze();
			if( res==1 ) {
				alert("帳密不通");
			} else if( res==2 ) {
				alert("主機連線逾時");
			} else if( res==99 ) {
				alert("連線成功!");
			} else {
				alert("發生不明錯誤");
			}
		},error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
	});
	windowUnfreeze();
}


$(document).ready(function() {
	
	init("host.html");

	windowFreeze("畫面初始中");
	
	$("#gd").jqGrid({
		url: "QueryHost",
		datatype: "json",
		type: "post",
		postData:{subsysId:"fOrder"},
	   	colNames:["主機IP","PORT","帳號","密碼"],
	   	colModel:[
	   		{name:"hostIP",index:"hostIP", editable:true, edittype:"text",editrules:{custom:true,required:true,custom_func:function(){
	   			var htip = $("input#hostIP").val();
	   			return [checkIP(htip),"請輸入格式正確的IP值"];
	   		}},editoptions: {size:15, maxlength: 15}},
	   		{name:"port",index:"port", editable:true, edittype:"text",editrules:{integer:true,required:true},editoptions: {size:5, maxlength: 5}},
	   		{
	   			name:"loginId", 
	   			editable:true, 
	   			edittype:"text"
	   		},
	   		{
	   			name:"loginPWD", 
	   			editable:true,
	   			hidden: true, hidedlg: true, editrules: { edithidden: true },
	   			edittype:"password"
	   		}
	   	],
	   	rowNum: 6,
	   	pager: "#pager",
	   	forceFit: true,
		rownumbers: true,
	   	viewrecords: true,	
		caption: "維護主機"
	}).jqGrid("navGrid","#pager",{add:true,edit:true,del:true,search:false,refresh:false},
	{	// Edit
		url: "EditHost",
		mtype: "POST",
		recreateForm: true,
		beforeShowForm: function () {
	        $('<a href="#">連線測試<span class="ui-icon ui-icon-disk"></span></a>').click( 
	        		function() {
	        			testHostConnection();
	            }).addClass("fm-button ui-state-default ui-corner-all fm-button-icon-left")
	              .prependTo("#Act_Buttons>td.EditButton");
	    },editData: {  hostIP:$("#hostIP").val(),subsysId:"fOrder",loginId:$("#loginId").val(),loginPWD:$("#loginPWD").val(),empId:$.cookie("empId") } 
	},
	{	// Add
		url: "EditHost",
		mtype: "POST",
		editData: {  subsysId:"fOrder",loginId:$("#loginId").val(),loginPWD:$("#loginPWD").val(),empId:$.cookie("empId") },	
		recreateForm: true,
		beforeShowForm: function () {
	        $('<a href="#">連線測試<span class="ui-icon ui-icon-disk"></span></a>').click( 
	        		function() {
	        			testHostConnection();
	            }).addClass("fm-button ui-state-default ui-corner-all fm-button-icon-left")
	              .prependTo("#Act_Buttons>td.EditButton");
	    }
	},
	{	// Delete
		url: "EditHost",
		mtype: "POST",
		delData: { 
			hostIP: function() { return getColVal("gd","hostIP",false); },
			subsysId:"fOrder",
			port: function() {	return getColVal("gd","port",false); },
			empId: $.cookie("empId")
		}
	});
	
	windowUnfreeze();
	
}).tooltip();
</script>

</head>
<body>
	<div id="header"></div>
	<p>
	<img src="pic/host.png" > 
	<p><p>
	<table id="gd"></table>
	<div id="pager"></div>
</body>
</html>